package nc.ui.hdysc.mainorder.uideal;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import nc.bs.framework.common.NCLocator;
import nc.hdysc.pub.BaseUtil;
import nc.hdysc.pub.PubParam;
import nc.itf.uap.IUAPQueryBS;
import nc.ui.hdysc.mainorder.dlg.CyOrderDlg;
import nc.ui.hdysc.mainorder.dlg.MeetingOrderDlg;
import nc.ui.pub.beans.MessageDialog;
import nc.ui.pub.bill.BillEditEvent;
import nc.ui.pub.bill.BillItem;
import nc.ui.pub.bill.BillModel;
import nc.ui.pub.bill.BillMouseEnent;
import nc.ui.pub.bill.BillTableMouseListener;
import nc.vo.hdysc.order.AggMainOrderVO;
import nc.vo.hdysc.order.HotelEatOrderVO;
import nc.vo.hdysc.order.MeetingOrderVO;
import nc.vo.hdysc.order.SceneryOrderVO;

import nc.vo.hdysc.order.MainOrderDetailVO;

import nc.vo.logging.Debug;
import nc.vo.pub.BusinessException;
import nc.vo.pub.VOStatus;

public class MeetingTableDeal extends AbstractOrderUIDeal implements BillTableMouseListener {

	private Map<String, MeetingOrderVO> meetingOrderMap;

	private IUAPQueryBS iq;

	MeetingOrderDlg dlg;

	public Map<String, MeetingOrderVO> getHotelEatOrderMap() {
		if (meetingOrderMap == null) {
			meetingOrderMap = new HashMap<String, MeetingOrderVO>();
		}
		return meetingOrderMap;
	}

	public MeetingTableDeal(nc.ui.hdysc.mainorder.ClientUI ui, String tableCode) {
		this.ui = ui;
		setCurrTableCode(tableCode);
		// this.currTableCode = tableCode;
		// ui.getBillCardPanel().removeBodyMouseListener(currTableCode);
		// ui.getBillCardPanel().addBodyMouseListener(currTableCode, this);
	}

	public IUAPQueryBS getDbQrySerive() {
		if (iq == null) {
			iq = NCLocator.getInstance().lookup(IUAPQueryBS.class);
		}

		return iq;
	}

	public MeetingOrderDlg getMeetingOrderDlg() {
		if (dlg == null) {
			dlg = new MeetingOrderDlg(ui);
		}
		return dlg;
	}

	@Override
	public void afterEdit(BillEditEvent e) throws Exception {
		return;
	}

	public void afterUpdate() throws Exception {

		MeetingOrderVO[] MeetingOrderVOArray = getMeetingOrderVOArrayInMainOrder();
		// BillModel bm = getBillModel(currTableCode);
		List<MeetingOrderVO> MeetingOrderVOList = new ArrayList<MeetingOrderVO>();
		getBillModel(currTableCode).clearBodyData();
		if (MeetingOrderVOArray != null) {
			for (MeetingOrderVO orderVO : MeetingOrderVOArray) {
				MeetingOrderVOList.add(orderVO);
			}
			ui.getHotelEatOrderDlg().addAll(getBillModel(currTableCode), MeetingOrderVOList);
		}
	}

	public MeetingOrderVO[] getMeetingOrderVOArrayInMainOrder() {
		AggMainOrderVO bill = (AggMainOrderVO) ui.getBufferData().getCurrentVO();
		if (bill == null)
			return null;
		MainOrderDetailVO[] mainDetails = (MainOrderDetailVO[]) bill.getChildrenVO();
		MeetingOrderVO[] MeetingOrderVOArray = null;
		for (int i = 0; i < mainDetails.length; i++) {
			if (mainDetails[i].getProduct_type() == PubParam.PRODUCTTYPE_MEETING) {
				MeetingOrderVOArray = mainDetails[i].getMeeting_list();
				break;
			}
		}
		return MeetingOrderVOArray;

	}

	public void mouse_doubleclick(BillMouseEnent e) {
		// TODO Auto-generated method stub

	}

}
